package me.leiusual.sharing.ui.mine

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.UserInfo
import me.leiusual.sharing.api.model.usertotal.UserTotal
import me.leiusual.sharing.pref.Store
import me.leiusual.sharing.pref.Token
import me.leiusual.sharing.pref.User
import me.leiusual.sharing.repository.UserRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.ui.account.AccountRegisterViewModelDelegate
import me.leiusual.sharing.ui.base.AbstractViewModel
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/15
 */
class MineHomeViewModel @Inject constructor(
    accountRegisterViewModelDelegate: AccountRegisterViewModelDelegate,
    private val userRepository: UserRepository,
    val token: Token,
    val user: User,
    val store: Store
) : ViewModel(), AccountRegisterViewModelDelegate by accountRegisterViewModelDelegate {

  // 用户信息

  private val _userInfo = MutableLiveData<Unit>()
  val userInfo: LiveData<Data<UserInfo.Response>> = switchMap(_userInfo) {
    userRepository.userInfo().toLiveData()
  }

  fun userInfo() {
    _userInfo.value = Unit
  }

  // 用户统计

  private val _userTotal = MutableLiveData<Unit>()
  val userTotal: LiveData<Data<UserTotal>> = switchMap(_userTotal) {
    userRepository.userTotal().toLiveData()
  }

  fun userTotal() {
    _userTotal.value = Unit
  }
}